The present application claims priority under 35 U.S.C. xc2xa7119 to Japanese Patent Application No. 2002-210211, filed Jul. 18, 2002, the entire disclosure of which is hereby incorporated by reference.
This invention relates to a two-dimensional code reading method, two-dimensional code reading program, recording medium for recording thereon the two-dimensional code reading program, two-dimensional code reading device, digital camera and portable terminal with the digital camera. Specifically, the present invention relates to a two-dimensional code reading method capable of reading accurately and immediately a two-dimensional code image taken obliquely with no contact with the object, two-dimensional code reading program for the same method, recording medium for recording the two-dimensional code reading program and the two-dimensional code reading device for reading a two-dimensional code according to the same method and program.
FIG. 1 shows representative kinds of codes which have been used for encoding information of the tags of products etc. in form of codes readable by computers. In comparison with bar code (xe2x80x9caxe2x80x9d in FIG. 1) containing information only in horizontal (or vertical) direction of one-dimension, the two-dimensional code containing information in the vertical and horizontal directions of two dimensions can holds a greater volume of information but requires longer time to read.
There are some methods for two-dimensional code, and the two-dimensional codes may be classified basically into two groups: stack type two-dimensional code (b) and matrix type two-dimensional code (c) as shown in FIG. 1. The stack type two-dimensional code is composed of a number of bar codes holding binary coded data and stacked in multiple layers (rows) in the direction perpendicular to that of arrangement of bars of each bar code. Rows are distinguished from each other by a start code and a stop code provided for each row.
The matrix type two-dimensional code is such that binary coded data is converted into cells that are arranged in two (horizontal and vertical) directions. The display area of the matrix code is represented by a pattern of dark (black) and bright (white) cells (squares in general). The angle and size of the black-and-white cell pattern are read and decoded.
To correctly decode a two-dimensional code, it is necessary to correctly discriminate by brightness/darkness of each bar or each cell. Therefore, it is important to determine a center position of each bar or each cell, which represents the position of data to be read.
An L-type guide cell and cut out symbol are provided for discriminating the direction of a symbol (i.e., two-dimensional code), which allow high-speed reading of two-dimensional code from all directions of 360xc2x0.
Representative stack type two-dimensional codes are CODE49, CODE16K and PDF417 and so on and matrix type two-dimensional codes are DATA CODE, QR CODE, MAXI CODE, Veri CODE, CODE1, Array Tag, CP CODE and Carla CODE and so on.
An example of matrix type two-dimensional code is QR code as shown in FIG. 2, which code is defined by JIS standard X0510. FIG. 2 is a view for explaining a summary of the QR code. As shown in FIG. 2, model 2 of QR code has specific position detecting element patterns A, B and C disposed at three corners for detecting the position of the QR code. Furthermore, QR code contains indexing patterns D0, D1, . . . , Dmax (max is model number depending on the number of cells making up QR code) arranged in the area for indexing the positions of respective cells. Timing patterns E and F for guiding the position of each cell are also disposed along the upper side (in a horizontal direction) and the left side (in a vertical direction) of the area of QR code.
In case of two-dimensional matrix code such as QR code, horizontal and vertical inspection lines are set so that they may join two pairs of opposite sides (horizontal sides and vertical sides) through center positions of timing patterns E and F arranged on the respective sides of the code area. In case of two-dimensional stack code made up of a stack of bar codes, an inspection line is set for each bar code by joining a pair of opposite sides in the direction of arrangement of bars of each bar code. In the two-dimensional matrix code, each cell is found at a cross point of respective inspection lines set in the above-described manner and information, and in the two-dimensional stack code, each cell is found at a cross point where an axis of a bar code layer and the inspection line intersect each other, then information contained in the cell is read and decoded for reading two-dimensional code.
FIG. 3 is a flowchart depicting the basic procedure of reading the QR code shown in FIG. 2. In the flowchart of FIG. 3, three position detecting element patterns A, B and C are found first by detecting specific features of position detecting patterns (Step S1), the symbol model number, i.e., the number of cells for recording data (the size of the two-dimensional code) is then detected (Step S2), center positions of respective cells composing the QR code are determined by calculation (Step S3), white (bright) and black (dark) are discriminated from image data corresponding to the respective cell positions and binary coded data xe2x80x9c0xe2x80x9d or xe2x80x9c1xe2x80x9d is generated (Step S4 and decoding of the QR code is finally conducted based on the binary coded data of each cell position (Step S5). Generally, since the calculation of cell center position at Step S3 and generation of binary coded data at Step S4 are carried out for each cell, the above sequential steps are repeated (as a double loop in vertical and horizontal directions).
For detecting the coordinate positions (image coordinate positions) of the QR code (Step S1), it is also possible to use additional information such as indexing patterns Di (i=0, 1, . . . , max) and/or timing patterns E and F. Furthermore, QR code is divided into areas based on the indexing patterns Di (i=0, 1, . . . , max) and timing patterns E and F to improve the accuracy of indexing. Alternatively, it is also possible to first detect the timing patterns E and F featured by alternations of bright (white) cell and dark (black) cell arranged between the position detecting element patterns A, B and C and find coordinates of center positions of the cells with respect to the position detecting element patterns A, B, C and timing patterns E, F, by image processing method, then determine the center positions of other cells by calculation using the detected coordinate.
However, it must be noted that the two-dimensional code image can not always be detected without distortion, for example, the two-dimensional code image read aslant may be often distorted. In particular, when the two-dimensional code is read at distance from the recording material (paper in many cases) by a non-contact type apparatus such as a digital camera and a portable telephone with a digital camera incorporated therein, the two-dimensional code image is probably distorted.
In this case, a kind of cell (i.e., information recorded in the cell) for the data cells disposed near to the position detecting element patterns A, B, C, the indexing patterns Di and timing patterns E, F can be accurately read owing to a small difference between the read position determined by calculation and the actual cell position. However, since the deviation of the calculated cell position to read from the actual cell position may be increased as the cell is apart further from the position detecting element patterns A, B, C, the indexing patterns Di and timing patterns E, F, it becomes difficult to accurately discriminate the kind of the cells distant from the above patterns.
A method for accurately reading two-dimensional code aslant read and distorted is disclosed in Japanese Patent Publication No. 2742555.
This method is to devise the setting of inspection lines for determining cell center positions based upon the fact that the distortion of two-dimensional code read at an angle of skew is proportional, to some degree.
In other words, four vertices of an area of a two-dimensional code read at a skew angle is identified by the pattern feature and inclination angle that indicates an inclination of two neighboring sides in the four sides forming the two-dimensional code area is determined first. Based on the position of each inspection line passing through a center position of each cell on one side, an inclination angle formed between each inspection line and each side is determined by proportional distribution from the inclination angle indicating the inclination of the side. A center position of each cell is identified by determining a cross point of respective inspection lines each having a proportionally distributed inclination angle. After this, the kind of the cell is read. To calculate the inclination angle of each inspection line, it is needed to use inverse trigonometric functions featured by a large amount of calculation. Therefore, it requires a large amount of time to identify the center positions of the cells of the two-dimensional code and interpret the two-dimensional code. Similarly, the application of this method to identify the center positions of bar codes of the stack type two-dimensional code also requires a large amount of calculation by using inverse trigonometric functions, resulting in consuming much time until the two-dimensional code is completely interpreted.
Japanese Laid-Open Patent Publication No. 2000-222517 discloses another method featured by processing the inspection lines setting. According to this publication, a method that a two-dimensional code area is considered as a trapezoid satisfying a certain condition and inspection lines for determining the cell position are set by joining respective pairs of dividing points preset on respective pairs of opposite sides of the trapezoid is disclosed. This method is intended to expedite the processing as to setting of inspection lines by eliminating the necessity of calculating an inclination angle at each time for the inspection line setting. Namely, if the two-dimensional code area in an image read can be considered as a trapezoid satisfying a certain condition, a setting position of the dividing point for one side can be set by proportionally distributed based on a ratio of lengths of two adjacent sides.
The above conventional methods are intended to achieve either more accurate reading of the two-dimensional code or shorter time of interpreting the two-dimensional code by devising how to set inspection lines for determining center positions of respective cells.
The method of Japanese Patent Publication No. 2742555 merely concerns how to accurately calculate the center position of each cell and never refers to how much time necessary for interpreting the two-dimensional code. In determining the center positions of respective cells of a two-dimensional code by the method of Japanese Patent Publication No. 2742555, it is needed to perform operations on inverse trigonometric functions each time of determining inclination angle of each inspection line, i.e., an inclination angle of each data cell at a center position of a timing cell. This means that the time required for calculating the inclination of the respective inspection lines may increase excessively in proportion with the number of cells of a two-dimensional code.
On the other hand, the method disclosed in Japanese Laid-Open Patent Publication No. 2000-222517 approximates a two-dimensional code image read as a square to a trapezoid satisfying a certain condition and, therefore, as compared with the method of Japanese Patent Publication No. 2742555, is featured by a shorter time necessary for setting inspection lines and interpreting the two-dimensional code but has lower accuracy of determining the center position of each cell by an intersection point of two inspection lines.
It is primary object of the present invention is to obtain accurate values of a two-dimensional code by converting a two-dimensional code image taken aslant by a digital camera into a normally taken two-dimensional code image information compensated for inclination of the image using inclination information and at the same time to achieve a considerable saving in time for determining center positions of respective data cells, i.e., for reading the two-dimensional code by using recurrence formulas expressing calculating equations for executing the image conversion.
Another object of the present invention is to provide a two-dimensional code reading method, which comprises processing steps of acquiring an image of a matrix type two-dimensional code composed of binary coded data represented by cells arranged in the horizontal and vertical directions, deciding the two-dimensional code area in the image, setting inspection lines each joining two opposites of 4 sides representing the boundary of the two-dimensional code area, which lines are used for determining center positions of data cells to be read and executing a decoding process to reproduce information of the two-dimensional code based on the inspection lines, wherein coefficients in image position calculating equations for determining coordinate positions of center positions of respective cells of the two-dimensional code compensated for inclination of the image by adding inclination information of the two-dimensional code are calculated for setting the inspection lines on the two-dimensional code image read based on coordinate positions of 4 points of the two-dimensional code area decided by the above two-dimensional code area deciding step.
Another object of the present invention is to provide the two-dimensional code reading method as described above, wherein the image position calculating equations for determining coordinate positions of center positions of respective cells in the two-dimensional code image are expressed by using recurrence formulas regarding the center positions of the respective cells to reduce a volume of calculations for determining the coordinate positions of center positions of respective cells compensated for its image inclination by adding inclination information of the two-dimensional code.
Another object of the present invention is to provide the two-dimensional code reading method as described above, wherein the coefficients in the image position calculating equations when calculating coordinate positions at four corners of the two-dimensional code area are integers obtained by dividing the coefficients by a predetermined same constant, thereby making it possible to determine the coordinate positions of the cell center positions by calculating with integers only.
Another object of the present invention is to provide the two-dimensional code reading method as described above, wherein a constant for dividing the coefficients symbolically determined for the image position calculating equations and selected from constants frequently and commonly used in the image position calculating equations is used to divide and convert the coefficients to smaller in size coefficients for making the two-dimensional code readable.
A further object of the present invention is to provide a two-dimensional code reading method which comprises processing steps of acquiring an image of a stack type two-dimensional code composed of a number of bar codes arranged in multiple layers in a direction perpendicular to a direction of arrangement of bars in each bar code representing data, deciding a two-dimensional code area in the image, setting an inspection line identifying a center position of each of the bar codes and joining one pair of opposite sides, in the direction of arrangement of bars in each bar code, of four sides representing the boundary of the decided two-dimensional code, and executing a decoding process to reproduce information of the two-dimensional code based on the inspection lines set by the inspection line setting processing, wherein coefficients in image position calculating equations for determining coordinate positions of center positions of respective bar codes compensated for the inclination of the image by adding inclination information of the two-dimensional code are calculated for setting the inspection lines on the two-dimensional code image read based on coordinate positions of 4 points within the two-dimensional code area deciding step.
Another object of the present invention is to provide a two-dimensional code reading program which describes the above-described two-dimensional code reading method by program codes executable by a computer.
Another object at the present invention is to provide a program recording medium which is readable by a computer and holding thereon the two-dimensional code reading program described previously.
A further object of the present invention is to provide a two-dimensional code reading device comprising an image capturing portion for capturing an image of a matrix type two-dimensional code composed of binary coded data represented by cells arranged in the vertical and horizontal directions, a two-dimensional code area deciding portion for deciding a two-dimensional code area in the two-dimensional code image, an inspection line setting portion for setting inspection lines identifying a center position of each of the cells, which inspection lines each join one of two pairs of opposites of 4 sides defining the boundary of the decided two-dimensional code area, and a decoding portion for reproducing information of the two-dimensional code based on the inspection lines, wherein the inspection line setting portion based on coordinate positions of 4 points within the two-dimensional code area decided by the two-dimensional code area deciding portion determines coefficients for image position calculating equations for determining coordinate positions of center positions of respective cells in the two-dimensional code compensated for the inclination of the image by adding information on the inclination of the two-dimensional code.
Another object of the present invention is to provide the above-mentioned two-dimensional code reading device in which each of the image position calculating equations for determining the coordinate positions of the center positions of the respective cells in the two-dimensional code image is expressed by a recurrence formula in respect to a center position of each of the cells, thereby realizing reduction of a volume of calculation for determining the coordinate positions of the center positions of respective cells compensated for image inclination by adding the inclination information of the two-dimensional code.
Another object of the present invention is to provide the above-mentioned two-dimensional code reading device in which the coefficients in the image position calculating equations when calculating coordinate positions at four corners of the two-dimensional code area are integers obtained by dividing the coefficients by a predetermined same constant, thereby making it possible to determine the coordinate positions of the cell center positions by calculating with integers only.
Another object of the present invention is to provide the above-mentioned two-dimensional code reading device in which a constant for dividing the coefficients symbolically determined for the image position calculating equations and selected from constants frequently and commonly used in the image position calculating equations is used to divide and convert the coefficients to smaller in size coefficients for making the two-dimensional code readable.
A further object of the present invention is to provide a digital camera incorporating the two-dimensional code reading device.
Still a further object of the present invention is to provide a portable telephone with a digital camera, which incorporates the two-dimensional code reading device.